/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hue;

import java.io.ByteArrayOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Hue
 */
public class GoServlet extends OpenURL {
    
    @Override
    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
        super.process(request, response);
        
        String requestURI = request.getRequestURI();
        if(request.getQueryString() != null) {
             requestURI += "?" + request.getQueryString();
        }
        String url = SERVER_URL + requestURI;
        /*
        String requestURI = request.getRequestURI();
        if(request.getQueryString() != null) {
             requestURI += "?" + request.getQueryString();
        }
        String url = SERVER_URL + "/go.php?requestURI=" + new String(Base64.encodeBase64(requestURI.getBytes()));
        */
        ByteArrayOutputStream baOut = new ByteArrayOutputStream();
        httpGet(request, response, url, baOut);
        String content = baOut.toString();
        baOut.close();
        
        StringBuilder sb = new StringBuilder();
        //sb.append("<a href='http://localhost'>continue</a><br>");
        //sb.append("<textarea>").append(content).append("</textarea>");
        sb.append("<script>window.location = 'http://localhost';</script>");
        response.getOutputStream().write(sb.toString().getBytes());
    }
}
